#!/bin/sh
#
# squid		Startup script for the SQUID HTTP proxy-cache.
#
# Version:	@(#)squid.rc  2.20  01-NOV-2009  ricardo.brito@planalto.gov.br
#
### BEGIN INIT INFO
# Provides:          squid
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Squid HTTP Proxy
### END INIT INFO


NAME=squid
DAEMON=/usr/local/squid/sbin/squid
LIB=/usr/lib/squid
PIDFILE=/var/run/$NAME.pid
SQUID_ARGS="-D -sYC"
CACHE=/usr/local/squid/var/cache/

. /lib/lsb/init-functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/squid/sbin:/usr/local/squid/bin

isCache() {
 [ -e $CACHE ] && echo "cache já existe" || echo "criando cache..."; $DAEMON -z;   
 exit 0
}

start() {
 echo 'function start'
 isCache 
 [ $? = 0 ] && status > /dev/null || echo " já está rodando"
 echo $?
}

stop() {
 #echo 'function stop'
 status > /dev/null
 echo $?
 [ $? = 0 ] && $DAEMON -k shutdown; echo "processo finalizado" || echo "já está finalizado";
}

status() {
 #echo 'function status'
 [ ! -f /var/run/$NAME.pid ] && echo "not Listen" || echo "Listen";
 # echo $NAME $?
 [ $? = 0 ] && echo "`netstat -nalpt|grep -i listen|grep squid`";
}

reload() {
 #echo 'function reload'
 echo "Aplicando atualizações...";
 $DAEMON -k reconfigure && echo "concluido!" || echo "Erro!!";
}

case "$1" in
	start)
	 start;
	;;
	stop)
	 stop;
	;;
	restart)
	 stop;
	 start;
	;;
	reload|force-reload)
	 reload;
	;;
	status)
	 status;
	;;
	*)                                                                                                                                                     
          echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart}"                                                                           
          exit 3                                                                                                                                             
          ;;
esac;
exit 0;
